{include file='common/head' /}
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<body>
<div class="x-nav">
          <span class="layui-breadcrumb" style="visibility: visible;">
                  <a><cite>商品管理</cite></a><span lay-separator="">/</span>
                  <a><cite>规格模板</cite></a>
              </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="value"  placeholder="规格名称/规格值" autocomplete="off" class="layui-input" value="{$get.value|default=''}">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <select name="type" lay-verify="required">
                                {$searType = isset($get.type) ? $get.type : 0}
                                <option value="0" {$searType == 0 ? 'selected="selected"' : ''}>规格名称</option>
                                <option value="1" {$searType == 1 ? 'selected="selected"' : ''}>规格值</option>
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-header">
                    <button class="layui-btn" onclick="xadmin.open('新增规格模板','/admin/product/specificationEdit')">
                        <i class="layui-icon"></i>添加规格模板</button>
                    <span style="line-height:40px;float: right;">共有数据：{$count} 条</span>
                </div>
                <div class="layui-card-body ">
                    <table class="layui-table layui-form">
                        <thead>
                        <tr>
                            <th style="text-align: center;">名称/值</th>
                            <th style="text-align: center;">排序</th>
                            <th style="text-align: center;">是否显示</th>
                            <th style="text-align: center;">时间</th>
                            <th style="text-align: center;">菜单操作</th>
                        </thead>
                        <tbody class="x-cate">
                        {volist name="list" id="v"}
                        <tr cate-id='{$v.id}' fid='0' >
                            <td  style="text-align: center;">
                                <i class="layui-icon x-show" status='true'>&#xe623;</i>{$v.value}
                            </td>
                            <td  style="text-align: center;">{$v.sort}</td>
                            <td  style="text-align: center;">
                                {$v.is_show == 1 ?
                                '<button type="button" class="layui-btn layui-btn-normal layui-btn-xs"><i class="layui-icon ">&#xe605;</i></button>' :
                                '<button type="button" class="layui-btn layui-btn-danger layui-btn-xs"><i class="layui-icon">&#x1006;</i></button>';
                                }
                            </td>
                            <td style="text-align: center;">{:date('Y-m-d H:i:s',$v['upd_time'])}</td>
                            <td style="text-align: center;" class="td-manage">
                                <button class="layui-btn layui-btn layui-btn-xs"  onclick="xadmin.open('编辑','/admin/product/specificationEdit?id={$v.id}')" ><i class="layui-icon">&#xe642;</i>编辑</button>
                                <button class="layui-btn-danger layui-btn layui-btn-xs"  onclick="menu_del(this,{$v['id']})" href="javascript:;" ><i class="layui-icon">&#xe640;</i>删除</button>
                            </td>
                        </tr>
                        {volist name="v['son']" id="vo"}
                        <tr cate-id='{$vo.id}' fid='{$v.id}' >
                            <td style="text-align: center;">&nbsp;&nbsp;
                                ├{$v.value}：<font color="#01AAED">{$vo.value}</font>
                            </td>
                            <td  style="text-align: center;">{$vo.sort}</td>
                            <td  style="text-align: center;"><button type="button" class="layui-btn layui-btn-normal layui-btn-xs"><i class="layui-icon ">&#xe605;</i></button></td>
                            <td style="text-align: center;">{:date('Y-m-d H:i:s',$v['upd_time'])}</td>
                            <td style="text-align: center;" class="td-manage">
                                <button class="layui-btn layui-btn layui-btn-xs"  onclick="xadmin.open('编辑','/admin/product/specificationEdit?id={$v.id}')" ><i class="layui-icon">&#xe642;</i>编辑</button>
                                <button class="layui-btn-danger layui-btn layui-btn-xs"  onclick="menu_del(this,{$vo['id']})" href="javascript:;" ><i class="layui-icon">&#xe640;</i>删除</button>
                            </td>
                        </tr>
                        {/volist}
                        {/volist}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form'], function(){
        form = layui.form;
    });

    /*删除*/
    function menu_del(obj,id){
        layer.confirm('确认要删除吗？',{icon: 8,title: '提示'},function(index){
            $.ajax({
                url:"{:url('Product/specificationDel')}",
                type: "post",
                data:{id:id},
                dataType:"json",
                success:function (res) {
                    if(res.code == 200){
                        $(obj).parents("tr").remove();
                        layer.msg(res.msg, {icon: 1,time:1000});
                    }else{
                        layer.alert(res.msg, {icon:2,time:1000});
                    }
                },
                error:function(e){
                    layer.alert("网络错误", {icon:5,time:1000});
                },
            });
        });
    }

    // 分类展开收起的分类的逻辑
    //
    $(function(){
        $("tbody.x-cate tr[fid!='0']").hide();
        // 栏目多级显示效果
        $('.x-show').click(function () {
            if($(this).attr('status')=='true'){
                $(this).html('&#xe625;');
                $(this).attr('status','false');
                cateId = $(this).parents('tr').attr('cate-id');
                $("tbody tr[fid="+cateId+"]").show();
            }else{
                cateIds = [];
                $(this).html('&#xe623;');
                $(this).attr('status','true');
                cateId = $(this).parents('tr').attr('cate-id');
                getCateId(cateId);
                for (var i in cateIds) {
                    $("tbody tr[cate-id="+cateIds[i]+"]").hide().find('.x-show').html('&#xe623;').attr('status','true');
                }
            }
        })
    })

    var cateIds = [];
    function getCateId(cateId) {
        $("tbody tr[fid="+cateId+"]").each(function(index, el) {
            id = $(el).attr('cate-id');
            cateIds.push(id);
            getCateId(id);
        });
    }

</script>
</body>
{include file='common/footer' /}
